package com.xxgc.spring.aspect;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;
//把这个类交给Spring 并且告诉Spring这是一个切面类
@Component
@Aspect
public class UserLoginAspect {
    @Pointcut("execution(* com.xxgc.spring.service.impl.UserLoginService.select*(..))")
    public void myPoint(){}

    @Before("execution(* com.xxgc.spring.service.impl.UserLoginService.*(..))")
    public void before(){
        System.out.println("前置增强");
    }

    @AfterReturning("UserLoginAspect.myPoint()")
    public void afterReturning(){
        System.out.println("后置增强");
    }

    @After("execution(* com.xxgc.spring.service.impl.UserLoginService.select*(..))")
    public void after(){
        System.out.println("最终通知");
    }

    @AfterThrowing("execution(* com.xxgc.spring.service.impl.UserLoginService.select*(..))")
    public void afterThrowing(){
        System.out.println("异常通知");
    }

    @Around("execution(* com.xxgc.spring.service.impl.UserLoginService.select*(..))")
    public Object around(ProceedingJoinPoint pjp) throws Throwable {
        System.out.println("环绕前置");
        //执行目标方法
        Object proceed = pjp.proceed();
        System.out.println("环绕后置");
        return proceed;
    }
}
